package com.slz3.business.module.financeManagement.finReconciliationManage.service;

import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Repositorys;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.steward.PageableSteward;
import com.slz3.business.module.financeManagement.finReconciliationManage.domain.FinReconciliationManage;
import com.slz3.business.module.financeManagement.finReconciliationManage.domain.FinReconciliationManageFactory;
import com.slz3.business.module.financeManagement.finReconciliationManage.steward.FinReconciliationManageSpecification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

@Slf4j
@Service
public class FinReconciliationManageServiceImpl implements FinReconciliationManageService {
    @Override
    public FinReconciliationManage save(FinReconciliationManage finReconciliationManage) {
        return Repositorys.finReconciliationManage.save(FinReconciliationManageFactory.initBaseFields(finReconciliationManage));
    }

    @Override
    public Page<FinReconciliationManage> page(MultiValueMap<String, String> params) {
        Page<FinReconciliationManage> finReconciliationManagePage = Repositorys.finReconciliationManage.findAll(
                FinReconciliationManageSpecification.findJoin(params), PageableSteward.extract(params)
        );
        return finReconciliationManagePage;
    }


    @Override
    public FinReconciliationManage modify(FinReconciliationManage finReconciliationManageNew) {
        return Repositorys.finReconciliationManage.saveAndFlush(FinReconciliationManageFactory.initBaseFields(finReconciliationManageNew));
    }

    @Override
    public Optional<FinReconciliationManage> single(UUID uuid) {
        return Repositorys.finReconciliationManage.findById(uuid);
    }

    @Override
    public List<FinReconciliationManage> findAllByUuids(Iterable<UUID> uuids) {
        return Repositorys.finReconciliationManage.findAllById(uuids);
    }

    @Override
    public List<FinReconciliationManage> delete(List<FinReconciliationManage> finReconciliationManageList) {
        finReconciliationManageList.stream().forEach(item -> {
            item.setValidFlag(ValidFlag.DEL);
            FinReconciliationManageFactory.initBaseFields(item);
        });
        return Services.finReconciliationManageTransactional.batchModify(finReconciliationManageList);
    }

}
